USA manage to decrease the number of both species in most of its states, leaving San Francisco with a minor density of both types.Africa overall, managed to eliminate both types when we compare data from 2004 to 2013, however Angola still struggle with Aedes aegypti.
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
Because of the strong, linear relationship between seniors mean incomes and young and adult mean incomes a linear regression model would be suitable to model the relationship between mean incomes among seniors, and mean income among young and adults. However, there is a potential risk for multicollinearity between the independent variables young and adult.
The advantage of these two plots is that they make it easier to compare the mean incomes between different counties.
library(ggplot2)
library(plotly)
library(plotly)
library(knitr)
library(tidyverse)
library(mapboxapi)
library(dplyr)
library(tmap)
library(plyr)
#import data
data <- read.csv("aegypti_albopictus.csv")
#Adding Mapbox Token << using mapbox account
mapboxToken <- paste("pk.eyJ1Ijoibm9ndWQiLCJhIjoiY2t0cG1qbGkxMDJuZTJva2dvZ3cxcnpseSJ9._Kyu7Zcuv5iqZPpq7OJWYQ", collapse="")
#Store the Token in a enviroment veriable
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
############
####1.1#####
############
data_13<-filter(data, YEAR == "2013")
fig_13 <- data_13
fig_13 <- fig_13 %>%
plot_ly(
lat = ~Y,
lon = ~X,
color = ~VECTOR,
mode = "markers",
width = 1000,
height = 900,
size = 1,
type = 'scattermapbox',
hovertext = data_13[,"COUNTRY"])
fig_13 <- fig_13 %>%
layout(
mapbox = list(
style = 'dark',
zoom =2.5),
showlegend = TRUE,
title = 'Distribution of the two types of mosquitos in the world Year 2013',
hovermode = TRUE)
fig_13 <- fig_13 %>%
config(mapboxAccessToken = Sys.getenv("MAPBOX_TOKEN"))
fig_13
###
data_04<-filter(data, YEAR == "2004")
fig_04 <- data_04
fig_04 <- fig_04 %>%
plot_ly(
lat = ~Y,
lon = ~X,
color = ~VECTOR,
width = 1000,
height = 900,
mode = "markers",
size = 1,
type = 'scattermapbox',
hovertext = data_04[,"COUNTRY"])
fig_04 <- fig_04 %>%
layout(
mapbox = list(
style = 'dark',
zoom =2.5),
showlegend = TRUE,
title = 'Distribution of the two types of mosquitos in the world Year 2004',
hovermode = TRUE)
fig_04 <- fig_04 %>%
config(mapboxAccessToken = Sys.getenv("MAPBOX_TOKEN"))
fig_04
############
####1.2#####
############
#data clean
m<-ddply(data, .(VECTOR,COUNTRY_ID,COUNTRY),nrow)
#Question 2
#plot_geo
fig<-plot_geo(m) %>%
add_trace(
z = m$V1, locations = m$COUNTRY_ID
)
fig <- fig %>% colorbar(title = "Mosquitos per Country ")
fig <- fig %>% layout(
title = 'Numbers of Mosquitos per Country Detected During all Study Period'
)
fig
############
####1.3#####
############
#Note that The available projections are 'equirectangular', 'mercator', 'orthographic', 'natural earth', 'kavrayskiy7', 'miller', 'robinson', 'eckert4', 'azimuthal equal area', 'azimuthal equidistant', 'conic equal area', 'conic conformal', 'conic equidistant', 'gnomonic', 'stereographic', 'mollweide', 'hammer', 'transverse mercator', 'albers usa', 'winkel tripel', 'aitoff' and 'sinusoidal'.
#Equirectangular projection with choropleth color log (𝑍𝑍)
g <- list(
projection = list(
type = 'equirectangular'
),
showland = TRUE,
landcolor = toRGB("LightGreen"),
showocean = TRUE,
oceancolor = toRGB("LightBlue"),
showlakes = FALSE,
lakecolor = toRGB("Blue"),
showrivers = FALSE,
rivercolor = toRGB("Blue"),
resolution = 50,
showland = FALSE,
landcolor = toRGB("#e5ecf6")
)
fig<-plot_geo(m) %>%
add_trace(
z = log(m$V1), locations = m$COUNTRY_ID
)
fig <- fig %>% colorbar(title = "Mosquitos per Country ")
fig <- fig %>% layout(
geo = g,
title = 'Numbers of Mosquitos per Country Detected During all Study Period'
)
fig
###
#Conic equal area projection with choropleth color log (zz)
g <- list(
projection = list(
type = 'conic equal area'
),
showland = TRUE,
landcolor = toRGB("LightGreen"),
showocean = TRUE,
oceancolor = toRGB("LightBlue"),
showlakes = FALSE,
lakecolor = toRGB("Blue"),
showrivers = FALSE,
rivercolor = toRGB("Blue"),
resolution = 50,
showland = FALSE,
landcolor = toRGB("#e5ecf6")
)
fig<-plot_geo(m) %>%
add_trace(
z = log(m$V1), locations = m$COUNTRY_ID
)
fig <- fig %>% colorbar(title = "Mosquitos per Country ")
fig <- fig %>% layout(
geo = g,
title = 'Numbers of Mosquitos per Country Detected During all Study Period'
)
fig
#############
#### 1.4 ####
#############
databr$X1<-cut_interval(databr$X,n=100)
databr$Y1<-cut_interval(databr$Y,n=100)
databm<- databr %>%
group_by(databr$X1,databr$Y1) %>%
dplyr::summarise(X_mean = mean(X), Y_mean = mean(Y), N = n())
##
fig_xy <- databm
fig_xy <- fig_xy %>%
plot_ly(
lat = ~Y_mean,
lon = ~X_mean,
color = ~N,
width = 1000,
height = 900,
mode = "markers",
size = 1,
type = 'scattermapbox')
fig_xy <- fig_xy %>%
layout(
mapbox = list(
style = 'dark',
zoom =2.5),
showlegend = TRUE,
title = 'Regions in Brazil that are most infected by mosquitoes',
hovermode = TRUE)
fig_xy <- fig_xy %>%
config(mapboxAccessToken = Sys.getenv("MAPBOX_TOKEN"))
fig_xy
#############
#### 2.1 ####
#############
rds <- readRDS("gadm36_SWE_1_sf.rds")
df <- read.csv("000000KD_20210917-142328.csv")
df_wide <- reshape(df,
timevar = "age",
idvar = c("region"),
direction = "wide")
colnames(df_wide)[2:4] <- c("Young", "Adult", "Senior")
#############
#### 2.2 ####
#############
fig_young <- df_wide %>%
plot_ly(
y = ~Young,
name = 'Young',
type = 'violin',
meanline = list(
visible = T
),
x0 = 'Young'
)
fig_adult <- df_wide %>%
plot_ly(
y = ~Adult,
name = 'Adult',
type = 'violin',
meanline = list(
visible = T
),
x0 = 'Adult'
)
fig_senior <- df_wide %>%
plot_ly(
y = ~Senior,
name = 'Senior',
type = 'violin',
meanline = list(
visible = T
),
x0 = 'Senior'
)
violin_plots <- subplot(fig_young, fig_adult, fig_senior, shareY = TRUE) %>%
layout(yaxis = list(title = "Income"))
violin_plots
### Alternatively ###
df[which(df$age == "18-29 years"),"age"] <- "Young"
df[which(df$age == "30-49 years"),"age"] <- "Adult"
df[which(df$age == "50-64 years"),"age"] <- "Senior"
fig <- df %>%
plot_ly(
x = ~age,
y = ~X2016,
split = ~age,
type = 'violin',
meanline = list(
visible = T
)
) %>%
layout(xaxis = list(title = "Age group"), yaxis = list(title = "Income"))
fig
#############
#### 2.3 ####
#############
s <- with(df_wide, interp(Young, Adult, Senior, duplicate = "mean"))
plot_ly(x=~s$x, y=~s$y, z=~s$z, type="surface") %>%
layout(scene = list(xaxis = list(title = "Young"),
yaxis = list(title = "Adult"),
zaxis = list(title = "Senior")))
#############
#### 2.4 ####
#############
df_wide$region <- unlist(lapply(strsplit(df_wide$region, " "), function(x) { x[2] }))
df_wide$region[which(df_wide$region == "Västra")] <- "Västra Götaland"
rds$NAME_1[which(rds$NAME_1 == "Orebro")] <- "Örebro"
rds <- merge(rds, df_wide[], by.x = "NAME_1", by.y = "region")
p_young <- plot_ly() %>% add_sf(data=rds, split=~NAME_1, color=~Young, showlegend=F, alpha=1)
p_adult <- plot_ly() %>% add_sf(data=rds, split=~NAME_1, color=~Adult, showlegend=F, alpha=1)
p_maps <- subplot(p_young, p_adult)
p_maps
#############
#### 2.5 ####
#############
p_young <- p_young %>% add_markers(x = 15.577691, y = 58.399103, text = "Linköping",
marker = list(color = "red"))
p_young
Simon and Mohamed devised the whole assignment together, the main conceptual ideas and codes outline. Mohamed worked out Assignment 1 (Visualization of mosquito’s populations), and the report creation using r markdown, Simon worked out Assignment 2 (Visualization of income in Swedish households).